*******************************************************************************
* this do file is for: 1) clean data used in Kern and Hainmueller, 2009, PA;
*                      2) replicating KH (2009, PA);
*                      3) generate cleaned data;
*                      4) generate extension results for KH (2009, PA).
* data used in this file: za6008.dta
* date: June 14, 2021
*******************************************************************************

* log file
log using "C:\Users\arthu\Dropbox\research\mte_at\codes\replication\results\kh_2009pa_replication.log"

* global command
global data "C:\Users\arthu\Dropbox\research\mte_at\codes\replication\data"
global merge1_1 "C:\Users\arthu\Dropbox\research\mte_at\codes\replication\results"

******************************************************************************
* compute: replicate regression results (LATE results) in the paper
* replicate Table F1: Replicated LATE Estimates in Kern and Hainmueller (2009)
******************************************************************************

use "$data\kh_2009pa_cleaned.dta", clear

* global variables
global communism lenin_kh east_ger_kh poli_pow_kh
global communism_b lenin east_ger poli_pow
global limit_cov age gender father_occ mother_occ
global full_cov age gender father_occ mother_occ marital numb_child educ prof_quali inc employ

* compute: table 3 (drop missing values on y, t, and z; results are qualitatively similar)
foreach var of varlist $communism{
  
  * compute: LATE
  ivreg2 `var' (treatment = iv)
  outreg2 using "$merge1_1\table_f1_panel_a.xls", append

}

******************************************************************************
* compute: extending regression results in the paper with binary outcome
* replicate Table F1: Replicated LATE Estimates in Kern and Hainmueller (2009)
******************************************************************************

* compute: tsls with binary outcome
 foreach var of varlist $communism_b{
  
  * compute: LATE
  ivreg2 `var' (treatment = iv)
  outreg2 using "$merge1_1\table_f1_panel_b.xls", append

}

***********************************************************************
* replicate Table H1: Summary Statistics in Kern and Hainmueller (2009)
***********************************************************************

asdoc sum $communism_b treatment iv $limit_cov, ///
  save($merge1_1\table_h1.doc)

****************
* close log file
****************

log close
